// pages/addressChoose/addressChoose.js
var app=getApp()
Page({
  data:{},
  actionSheetTap: function (e) {
    var url = app.data.url
    var id = e.currentTarget.dataset.index
    wx.showActionSheet({
      itemList: ['编辑', '删除'],
      success: function (e) {
        console.log(e.tapIndex);
        if (e.tapIndex == 0) {
          wx.navigateTo({
            url: '../address-add/address-add?id=' + id + ''
          });
        }
        if (e.tapIndex == 1) {
          wx.request({
            url: '' + url + '/shop/order/deletereceiptaddress',
            data: { id: id },
            header: {
              'Content-Type': 'application/json'
            },
            success: function (res) {
              console.log(res)
              if (res.Status == 'ok') {
                wx.redirectTo({
                  url: '../address-list/address-list',
                })
              }
            },
            error: function (res) {
              console.log(res)
            }
          })
        }
      }
    })
  },
  onLoad:function(options){
    var that = this
    var url = app.data.url
    var openid = wx.getStorageSync('user').openid
    //收货地址列表
    wx.request({
      url: '' + url + '/Shop/UserCenter/GetReceiptAddress2',
      data: { openid: '123', storeid: '6002' },
      header: {
        'Content-Type': 'application/json'
      },
      success: function (res) {
        that.setData({
          list: res.data.Rows
        })
      },
      error: function (res) {
        console.log(res)
      }
    })
  },
  onReady:function(){
    // 页面渲染完成
  },
  onShow:function(){
    // 页面显示
  },
  onHide:function(){
    // 页面隐藏
  },
  onUnload:function(){
    // 页面关闭
  }
})